package com.example.car.vm

import com.example.car.api.CarApiService
import com.example.car.entity.CarAddEntity
import com.example.car.entity.CarAddParam
import com.example.car.entity.CarPayParam
import com.example.car.model.CarRepository
import com.example.car.model.CarResultData
import com.example.common.view.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class CarViewModel @Inject constructor(private val apiService: CarApiService):BaseViewModel<CarRepository,CarResultData<List<CarAddEntity>>>(){
    fun getAddCar(carAddParam: CarAddParam){
        mViewModelScope.launch (mDispatcher){
            try {
                val result=apiService.getAddCar(carAddParam)
                val res=CarResultData(
                    state = result.state,
                    msg = result.msg,
                    data = listOf(result.data)
                )
                mSuccessLiveData.postValue(res)
            }catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}